package com.kl.controller;


import com.kl.em.ConstantEnum;
import com.kl.em.Result;
import com.kl.entity.TbAreas;
import com.kl.entity.TbCities;
import com.kl.entity.TbProvinces;
import com.kl.service.ITbAreasService;
import com.kl.service.ITbCitiesService;
import com.kl.service.ITbProvincesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static javafx.beans.binding.Bindings.select;

/**
 * <p>
 * 行政区域县区信息表 前端控制器
 * </p>
 *
 * @author author
 * @since 2021-11-03
 */
@RestController
@RequestMapping("/areas")
@Api(value = "县")
public class TbAreasController {
    @Autowired
    private ITbAreasService iTbAreasService;
    @Autowired
    private ITbCitiesService iTbCitiesService;
    @Autowired
    private ITbProvincesService provincesService;

    @ApiOperation(value = "根据id得出区")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "query"),
    })
    @GetMapping("/getareas")
    public Result getareas(@RequestParam Integer id) {
        Map<String,Object> map = new HashMap<>();
        map.put("cityid",id);
        List<TbAreas> list =  iTbAreasService.select(map);
        return Result.build(ConstantEnum.SUCCESS).setResult(list);
    }
    @ApiOperation(value = "根据id得出市")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "query"),
    })
    @GetMapping("/getcity")
    public Result getcity(@RequestParam Integer id) {
        Map<String,Object> map = new HashMap<>();
        map.put("provinceid",id);
        List<TbCities   > list =  iTbCitiesService.select(map);
        return Result.build(ConstantEnum.SUCCESS).setResult(list);
    }
    @ApiOperation(value = "根据id得出省")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "query"),
    })
    @GetMapping("/TbProvinces")
    public Result getprovinces(@RequestParam Integer id) {
        Map<String,Object> map = new HashMap<>();
        map.put("provinceid",id);
        List<TbProvinces> list =  provincesService.select(map);
        return Result.build(ConstantEnum.SUCCESS).setResult(list);
    }
}
